package com.skydonkey.dao;

import com.github.pagehelper.Page;
import com.skydonkey.pojo.po.VideoMyLiked;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VideoMyLikedMapper {

    @Insert("INSERT INTO videos_my_likes (uid, video_id) VALUES (#{uid}, #{videoId})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int insertMyLikedVideo(VideoMyLiked videoMyLiked);

    @Delete("DELETE FROM videos_my_likes WHERE video_id = #{videoId} and uid = #{uid}")
    int deleteMyLikedVideo(VideoMyLiked videoMyLiked);

    @Select("SELECT * FROM videos_my_likes WHERE uid = #{uid}")
    Page<VideoMyLiked> getLikedVideosByUid(Long uid);

    @Select("SELECT COUNT(*) FROM videos_my_likes WHERE uid = #{uid} AND video_id = #{videoId}")
    int isVideoLikedByUser(@Param("uid") Long uid, @Param("videoId") Long videoId);


    @Select("SELECT COUNT(1) FROM videos_my_likes WHERE video_id = #{videoId}")
    Long getVideoLikedCount(@Param("videoId") Long videoId);
}
